package com.maduar.demo.algo.dp;

/**
 * Description:
 *
 * @author maduar maduar@163.com
 * @date 2021-03-27 00:33
 */
public class SubArray {

    public static int maxSubArray(int[] arr) {
        int len = arr.length;
        int sum = 0;
        int max = 0;

        for (int i = 0; i < len; i++) {
            sum += arr[i];
            if (sum > max) {
                max = sum;
            }
            if (sum < 0) {
                sum = 0;
            }
        }

        return max;
    }
}
